package com.liucxu.zimuzu.View.Fragement;

import android.widget.ListView;
import android.widget.RadioGroup;

import com.liucxu.zimuzu.Base.BaseFragment;
import com.liucxu.zimuzu.Model.Bean.ChannelResourceBean;
import com.liucxu.zimuzu.Model.Bean.ChannelResourceEntity;
import com.liucxu.zimuzu.Presenter.IChannelPresenter;
import com.liucxu.zimuzu.Presenter.Impl.ChannelPresenterImpl;
import com.liucxu.zimuzu.R;
import com.liucxu.zimuzu.View.Adapter.ChannelResourceAdapter;
import com.liucxu.zimuzu.View.IView.IChannelView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Channel频道Fragment
 * Created by liukanshan on 2016/12/25.
 */

public class ChannelFragment extends BaseFragment implements IChannelView {

    private RadioGroup channel_radio_group;
    private RadioGroup area_radio_group;
    private RadioGroup category_radio_group;
    private HashMap<String, String> values = new HashMap<>();
    private List<ChannelResourceEntity> list = new ArrayList<>();
    private IChannelPresenter mChannelPresenter;
    private ListView channel_grid;
    private ChannelResourceAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_channel;
    }

    @Override
    public void setupView() {
        channel_radio_group = $(R.id.channel_radio_group);
        area_radio_group = $(R.id.area_radio_group);
        category_radio_group = $(R.id.category_radio_group);
        channel_grid=$(R.id.channel_grid);
        adapter = new ChannelResourceAdapter(getActivity(), list);
        channel_grid.setAdapter(adapter);
        channel_radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int id) {
                switch (id) {
                    case R.id.channel_radio_btn_all:
                        values.put("channel", "");
                        break;
                    case R.id.channel_radio_btn_movie:
                        values.put("channel", "movie");
                        break;
                    case R.id.channel_radio_btn_tv:
                        values.put("channel", "tv");
                        break;
                    case R.id.channel_radio_btn_open_class:
                        values.put("channel", "openclass");
                        break;
                    case R.id.channel_radio_btn_documentary:
                        values.put("channel", "documentary");
                        break;
                }
                mChannelPresenter.getFetchList(values);
            }
        });
        //区域
        area_radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int id) {
                switch (id) {
                    case R.id.area_radio_btn_all:
                        values.put("area", "");
                        break;
                    case R.id.area_radio_btn_us:
                        values.put("area", "美国");
                        break;
                    case R.id.area_radio_btn_jp:
                        values.put("area", "日本");
                        break;
                    case R.id.area_radio_btn_china:
                        values.put("area", "大陆");
                        break;
                    case R.id.area_radio_btn_hk:
                        values.put("area", "香港");
                        break;
                }
                mChannelPresenter.getFetchList(values);
            }
        });

        //类别
        category_radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int id) {
                switch (id) {
                    case R.id.category_radio_btn_all:
                        values.put("category", "");
                        break;
                    case R.id.category_radio_btn_action:
                        values.put("category", "动作");
                        break;
                    case R.id.area_radio_btn_war:
                        values.put("category", "战争");
                        break;
                    case R.id.area_radio_btn_plot:
                        values.put("category", "剧情");
                        break;
                    case R.id.area_radio_btn_comedy:
                        values.put("category", "喜剧");
                        break;
                }
                mChannelPresenter.getFetchList(values);
            }
        });
    }

    @Override
    public void setupData() {
        values.put("channel", "");
        values.put("area", "");
        values.put("category", "");
        mChannelPresenter=new ChannelPresenterImpl(this);
        mChannelPresenter.getFetchList(values);
    }

    @Override
    public void setChannel(ChannelResourceBean bean) {
        if (bean.getData() != null && bean.getData().getList() != null) {
            list.clear();
            list.addAll(bean.getData().getList());
            adapter.setDatas(list);
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showError(String errMsg) {

    }
}
